home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-07 | 16.1 KB | 590 lines | [TEXT/KAHL] |
- ///--------------------------------------------------------------------------------------
- // BlitPixie.c
- //
- // Created: Thursday, September 24, 1992 at 11:48 PM
- // By: Tony Myles
- //
- // Pieced together by Tony Myles and Ben Sharpe
- // Special thanks to Brigham Stevens and Sean Callahan
- //
- // Portions Copyright: © 1991-93 Tony Myles, All rights reserved worldwide.
- // Portions Copyright: © 1993 Ben Sharpe, All rights reserved worldwide.
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- #include <QDOffscreen.h>
- #endif
-
- #ifndef __FRAME__
- #include <Frame.h>
- #endif
-
- #ifndef __BLITPIXIE__
- #include <BlitPixie.h>
- #endif
-
-
- #define __UseCClipRect__
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixie
- //
- // copies the pixels from within pixRect from srcPixMapH to dstPixMapH
- //
- // assumes 8 bits per pixel
- // assumes pixmaps are the same size
- // assumes pixmaps are locked
- // assumes pixRect is long word aligned
- // assumes sourceRect and destRect are equalsize
- //
- ///--------------------------------------------------------------------------------------
-
- void BlitPixie(
- PixMapPtr sourceImage,
- PixMapPtr destImage,
- Rect *sourceRect,
- Rect *destRect,
- Rect *boundsRect)
- {
-
- register long *sourceMemPtr; // pointer to source image memory
- register long *destMemPtr; // pointer to dest image memory
- register long numRowsToCopy; // rows we are going to copy
- register long sourceRowLongsOffset; // rowBytes offset
- register long destRowLongsOffset; // rowBytes offset
- register long loop2Offset; // jump offset for partial inner loop
- register long loopsPerRow; // number of full inner loops to do
-
- long sourceStripRowBytes; // to clear high bit of rowbytes
- long destStripRowBytes; // to clear high bit of rowbytes
- long numRowLongs; // number of long words per row
- Rect blitRect; // area to blit from
- Rect dstBlitRect;
- char mmuMode; // 32-bit mode required
-
- // make a local copy so we can make some adjustments
- blitRect = *sourceRect;
- dstBlitRect = *destRect;
-
- #ifndef __UseCClipRect__
- asm
- {
- lea blitRect, a0
- lea dstBlitRect, a1
- movea.L boundsRect, a2
-
- tstT: move.w Rect.top(a1),d0
- cmp.w Rect.top(a2),d0
- bge @tstB
- move.w Rect.top(a2),d0
- sub.w Rect.top(a1),d0
- add.w d0,Rect.top(a0)
- move.w Rect.top(a2),Rect.top(a1)
- move.w Rect.top(a1),d0
- cmp.w Rect.bottom(a1),d0
- bge @EndBlit
- bra @tstL
-
- tstB: move.w Rect.bottom(a1),d0
- cmp.w Rect.bottom(a2),d0
- ble @tstL
- move.w Rect.bottom(a2),Rect.bottom(a1)
- move.w Rect.bottom(a1),d0
- cmp.w Rect.top(a1),d0
- ble @EndBlit
-
- tstL: move.w Rect.left(a1),d0
- cmp.w Rect.left(a2),d0
- bge @tstR
- move.w Rect.left(a2),d0
- sub.w Rect.left(a1),d0
- add.w d0,Rect.left(a0)
- move.w Rect.left(a2),Rect.left(a1)
- move.w Rect.left(a1),d0
- cmp.w Rect.right(a1),d0
- bge @EndBlit
- bra @doneClip
-
- tstR: move.w Rect.right(a1),d0
- cmp.w Rect.right(a2),d0
- ble @doneClip
- move.w Rect.right(a2),Rect.right(a1)
- move.w Rect.right(a1),d0
- cmp.w Rect.left(a1),d0
- ble @EndBlit
-
- doneClip:
- }
- #else
-
- // clip off the top so we dont write into random memory
- if (dstBlitRect.top < boundsRect->top)
- {
- blitRect.top += boundsRect->top - dstBlitRect.top;
- dstBlitRect.top = boundsRect->top;
- if (dstBlitRect.top >= dstBlitRect.bottom) return;
- }
- // clip off the bottom so we dont write into random memory
- else if (dstBlitRect.bottom > boundsRect->bottom)
- {
- dstBlitRect.bottom = boundsRect->bottom;
- if (dstBlitRect.bottom <= dstBlitRect.top) return;
- }
-
- // clip off the left so we dont write into random memory
- if (dstBlitRect.left < boundsRect->left)
- {
- blitRect.left += boundsRect->left - dstBlitRect.left;
- dstBlitRect.left = boundsRect->left;
-
- if (dstBlitRect.left >= dstBlitRect.right) return;
- }
- // clip off the right so we dont write into random memory
- else if (dstBlitRect.right > boundsRect->right)
- {
- dstBlitRect.right = boundsRect->right;
-
- if (dstBlitRect.right <= dstBlitRect.left) return;
- }
- #endif
-
- // high bit of pixMap rowBytes must be cleared
- sourceStripRowBytes = sourceImage->rowBytes & 0x7FFF;
-
- // high bit of pixMap rowBytes must be cleared
- destStripRowBytes = destImage->rowBytes & 0x7FFF;
- /*
- // calculate the address of the first byte of the source
- sourceMemPtr = (long *)(GetPixBaseAddr(&sourceImage) +
- (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- // calculate the address of the first byte of the destination
- destMemPtr = (long *)(GetPixBaseAddr(&destImage) +
- (destStripRowBytes * dstBlitRect.top) + dstBlitRect.left);
- */
- // calculate the address of the first byte of the source
- sourceMemPtr = (long *)(sourceImage->baseAddr +
- (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- // calculate the address of the first byte of the destination
- destMemPtr = (long *)(destImage->baseAddr +
- (destStripRowBytes * dstBlitRect.top) + dstBlitRect.left);
-
- // calculate the number of rows to copy
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // calculate the number of long words in a row
- numRowLongs = (dstBlitRect.right - dstBlitRect.left) >> 2;
-
- // calculate the long word offset from the end of one row to the start of the next
- sourceRowLongsOffset = ((sourceStripRowBytes >> 2) - numRowLongs) << 2;
-
- // calculate the long word offset from the end of one row to the start of the next
- destRowLongsOffset = ((destStripRowBytes >> 2) - numRowLongs) << 2;
-
- loopsPerRow = numRowLongs >> 4;
- loop2Offset = (16 - (numRowLongs - (loopsPerRow << 4))) << 1;
-
- // change to 32-bit addressing mode to access video memory
- // the previous addressing mode is returned in mmuMode for restoring later
- mmuMode = true32b;
- SwapMMUMode(&mmuMode);
-
- asm {
-
- loop1:
- move.L loopsPerRow,d0
- loop2:
- bne @1
- jmp @1(loop2Offset)
- @1:
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 16
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 15
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 14
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 13
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 12
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 11
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 10
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 9
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 8
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 7
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 6
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 5
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 4
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 3
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 2
- move.L (sourceMemPtr)+,(destMemPtr)+ ; 1
-
- subq.L #1,d0
- bpl @loop2
- endloop2:
-
- adda.L sourceRowLongsOffset,sourceMemPtr
- adda.L destRowLongsOffset,destMemPtr
- subq.L #1,numRowsToCopy
- bne @loop1
- endloop1:
- }
-
- // restore addressing mode back to what it was
- SwapMMUMode(&mmuMode);
- asm
- {
- @EndBlit:
- }
- }
-
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMask
- //
- // assumes 8 bits per pixel
- // assumes pixmaps are the same size
- // assumes pixmaps are locked
- // assumes pixRect is long word aligned
- // assumes sourceRect and destRect are equalsize
- ///--------------------------------------------------------------------------------------
-
- void BlitPixieMask(
- PixMapPtr maskImage,
- PixMapPtr sourceImage,
- PixMapPtr destImage,
- Rect *sourceRect,
- Rect *destRect,
- Rect *boundsRect)
- {
- register long *sourceMemPtr; // pointer to source memory
- register long *maskMemPtr; // pointer to mask memory
- register long *destMemPtr; // pointer to dest memory
- register long numRowsToCopy; // rows we are going to copy
- register long sourceRowLongsOffset; // rowBytes converted to long
- register long destRowLongsOffset; // rowBytes converted to long
- register long loop2Offset;
- register long loopsPerRow;
-
- long sourceStripRowBytes; // to clear high bit of rowbytes
- long destStripRowBytes; // to clear high bit of rowbytes
- long numRowLongs; // number of long words per row
- Rect blitRect; // area to blit from
- Rect dstBlitRect; // area to blit from and to
- char mmuMode; // 32-bit mode required
-
- // make a local copy so we can make some adjustments
- blitRect = *sourceRect;
- dstBlitRect = *destRect;
-
- #ifndef __UseCClipRect__
- asm
- {
- lea blitRect, a0
- lea dstBlitRect, a1
- movea.L boundsRect, a2
-
- tstT: move.w (a1),d0
- cmp.w (a2),d0
- bge @tstB
- move.w (a2),d0
- sub.w (a1),d0
- add.w d0,(a0)
- move.w (a2),(a1)
- move.w (a1),d0
- cmp.w Rect.bottom(a1),d0
- bge @EndBlit
- bra @tstL
-
- tstB: move.w Rect.bottom(a1),d0
- cmp.w Rect.bottom(a2),d0
- ble @tstL
- move.w Rect.bottom(a2),Rect.bottom(a1)
- move.w Rect.bottom(a1),d0
- cmp.w (a1),d0
- ble @EndBlit
-
- tstL: move.w Rect.left(a1),d0
- cmp.w Rect.left(a2),d0
- bge @tstR
- move.w Rect.left(a2),d0
- sub.w Rect.left(a1),d0
- add.w d0,Rect.left(a0)
- move.w Rect.left(a2),Rect.left(a1)
- move.w Rect.left(a1),d0
- cmp.w Rect.right(a1),d0
- bge @EndBlit
- bra @doneClip
-
- tstR: move.w Rect.right(a1),d0
- cmp.w Rect.right(a2),d0
- ble @doneClip
- move.w Rect.right(a2),Rect.right(a1)
- move.w Rect.right(a1),d0
- cmp.w Rect.left(a1),d0
- ble @EndBlit
-
- doneClip:
- }
- #else
-
- // clip off the top so we dont write into random memory
- if (dstBlitRect.top < boundsRect->top)
- {
- blitRect.top += boundsRect->top - dstBlitRect.top;
- dstBlitRect.top = boundsRect->top;
- if (dstBlitRect.top >= dstBlitRect.bottom) return;
- }
- // clip off the bottom so we dont write into random memory
- else if (dstBlitRect.bottom > boundsRect->bottom)
- {
- dstBlitRect.bottom = boundsRect->bottom;
- if (dstBlitRect.bottom <= dstBlitRect.top) return;
- }
-
- // clip off the left so we dont write into random memory
- if (dstBlitRect.left < boundsRect->left)
- {
- blitRect.left += boundsRect->left - dstBlitRect.left;
- dstBlitRect.left = boundsRect->left;
-
- if (dstBlitRect.left >= dstBlitRect.right) return;
- }
- // clip off the right so we dont write into random memory
- else if (dstBlitRect.right > boundsRect->right)
- {
- dstBlitRect.right = boundsRect->right;
-
- if (dstBlitRect.right <= dstBlitRect.left) return;
- }
- #endif
-
- // high bit of pixMap rowBytes must be cleared
- sourceStripRowBytes = sourceImage->rowBytes & 0x7FFF;
-
- // high bit of pixMap rowBytes must be cleared
- destStripRowBytes = destImage->rowBytes & 0x7FFF;
- /*
- // calculate the address of the first byte of the source
- sourceMemPtr = (long *)(GetPixBaseAddr(&sourceImage) + (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- // calculate the address of the first byte of the mask
- maskMemPtr = (long *)(GetPixBaseAddr(&maskImage) + (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- blitRect = dstBlitRect; // for speed
-
- // calculate the address of the first byte of the destination
- destMemPtr = (long *)(GetPixBaseAddr(&destImage) + (destStripRowBytes * blitRect.top) + blitRect.left);
- */
- // calculate the address of the first byte of the source
- sourceMemPtr = (long *)(sourceImage->baseAddr +
- (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- // calculate the address of the first byte of the mask
- maskMemPtr = (long *)(maskImage->baseAddr +
- (sourceStripRowBytes * blitRect.top) + blitRect.left);
-
- blitRect = dstBlitRect; // for speed
-
- // calculate the address of the first byte of the destination
- destMemPtr = (long *)(destImage->baseAddr +
- (destStripRowBytes * dstBlitRect.top) + dstBlitRect.left);
-
- // calculate the number of rows to copy
- numRowsToCopy = blitRect.bottom - blitRect.top;
-
- // calculate the number of long words in a row
- numRowLongs = (dstBlitRect.right - dstBlitRect.left) >> 2;
-
- // calculate the long word offset from the end of one row to the start of the next
- sourceRowLongsOffset = ((sourceStripRowBytes >> 2) - numRowLongs) << 2;
-
- // calculate the long word offset from the end of one row to the start of the next
- destRowLongsOffset = ((destStripRowBytes >> 2) - numRowLongs) << 2;
-
- loopsPerRow = numRowLongs >> 4;
- loop2Offset = (16 - (numRowLongs - (loopsPerRow << 4))) * 12;
-
- // change to 32-bit addressing mode to access video memory
- // the previous addressing mode is returned in mmuMode for restoring later
- mmuMode = true32b;
- SwapMMUMode(&mmuMode);
- asm {
-
- loop1:
- move.L loopsPerRow,d2
- loop2:
- bne @1
- jmp @1(loop2Offset)
- @1:
- // 16
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 15
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 14
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 13
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 12
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 11
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 10
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 9
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 8
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 7
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 6
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 5
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 4
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 3
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 2
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
- // 1
- move.L (destMemPtr),d1
- move.L (sourceMemPtr)+,d0
- eor.L d1,d0
- and.L (maskMemPtr)+,d0
- eor.L d1,d0
- move.L d0,(destMemPtr)+
-
- subq.L #1,d2
- bpl @loop2
- endloop2:
-
- adda.L sourceRowLongsOffset,sourceMemPtr
- adda.L sourceRowLongsOffset,maskMemPtr
- adda.L destRowLongsOffset,destMemPtr
- subq.L #1,numRowsToCopy
- bne @loop1
- endloop1:
- }
-
- // restore addressing mode back to what it was
- SwapMMUMode(&mmuMode);
- asm
- {
- @EndBlit:
- }
- }
-
-
-
- SW_PASCAL void BlitPixieEraseProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect)
- {
- BlitPixie(srcFrameP->framePix.pixMapP, dstFrameP->framePix.pixMapP, srcRect, dstRect, &dstFrameP->frameRect);
- }
-
- SW_PASCAL void BlitPixieDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect,
- RgnHandle maskRgn)
- {
- ShieldCursor(dstRect, topLeft(qd.thePort->portBits.bounds));
-
- BlitPixie(srcFrameP->framePix.pixMapP, dstFrameP->framePix.pixMapP, srcRect, dstRect, &dstFrameP->frameRect);
-
- ShowCursor();
- }
-
- SW_PASCAL void BlitPixieMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect)
- {
- BlitPixieMask(srcFrameP->maskPix.pixMapP, srcFrameP->framePix.pixMapP, dstFrameP->framePix.pixMapP, srcRect, dstRect, &dstFrameP->frameRect);
- }
-
-